package gui.menu.actions;

import file.handling.FileFormat;
import gui.Frame;

import java.awt.event.ActionEvent;
import java.io.File;

import javax.swing.AbstractAction;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;

public class OpenAction extends AbstractAction
{
   private static Icon icon = new ImageIcon("icons/open.png");
   /**
    * 
    */
   private static final long serialVersionUID = 1L;
   private Frame frame;
   /** Create this action for the given frame */
   public OpenAction(Frame frame)
   {

      super("Open...",icon);
      this.frame = frame;
   }

   @Override
   public void actionPerformed(ActionEvent arg0)
   {
      // TODO Auto-generated method stub

      String directory = frame.getPreferences().getDefaultPath();
      JFileChooser dialog = new JFileChooser(directory);
      dialog.addChoosableFileFilter(new FileFormat());
      dialog.showOpenDialog(null);

      File file = dialog.getSelectedFile();
      if (file != null)
      {
         frame.getPreferences().setDefaultPath(file.getPath());
         frame.openFile(file);
         //         new OpenFile(file, frame);
         frame.disableUndoRedo();

      }

   }

}
